Write a C# Sharp program to determine whether the string "birds" is a substring of a familiar

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to determine whether the string "birds" is a substring of a familiar. 

Note : Quotation 'two birds with one stone'.

Expected Output :

'birds' is in the string 'Kill two birds with one stone': True                   
'birds begins at character position 10

الأجوبة

using System;
class Example38
{
    public static void Main() 
    {
       string str1 = "Kill two birds with one stone";
       string str2 = "birds";
       bool x = str1.Contains(str2);
       Console.WriteLine("'{0}' is in the string '{1}': {2}",
                          str2, str1, x);
       if (x) {
          int index = str1.IndexOf(str2);
          if (index >= 0)
             Console.WriteLine("'{0} begins at character position {1}",
                               str2, index + 1);
       }
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...